public class Solution {
    public TreeNode mergeTrees(TreeNode t1, TreeNode t2) {
        if (t1 == null) {
            return t2;
        }
        if (t2 == null) {
            return t1;
        }
        TreeNode merged = new TreeNode(t1.val + t2.val);
        merged.left = mergeTrees(t1.left, t2.left);
        merged.right = mergeTrees(t1.right, t2.right);
        return merged;
    }

    // TreeNode 类定义
    public static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }

    // 辅助方法：创建二叉树
    public static TreeNode createTree(Integer[] values) {
        if (values == null || values.length == 0) return null;
        java.util.Queue<TreeNode> queue = new java.util.LinkedList<>();
        TreeNode root = new TreeNode(values[0]);
        queue.add(root);
        int i = 1;
        while (i < values.length) {
            TreeNode node = queue.poll();
            if (values[i] != null) {
                node.left = new TreeNode(values[i]);
                queue.add(node.left);
            }
            i++;
            if (i < values.length && values[i] != null) {
                node.right = new TreeNode(values[i]);
                queue.add(node.right);
            }
            i++;
        }
        return root;
    }

    // 辅助方法：打印树（层序遍历）
    public static void printTree(TreeNode root) {
        if (root == null) {
            System.out.println("Empty Tree");
            return;
        }
        java.util.Queue<TreeNode> queue = new java.util.LinkedList<>();
        queue.add(root);
        while (!queue.isEmpty()) {
            TreeNode node = queue.poll();
            System.out.print(node.val + " ");
            if (node.left != null) queue.add(node.left);
            if (node.right != null) queue.add(node.right);
        }
        System.out.println();
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        
        Integer[] values1 = {1, 3, 2, 5};
        Integer[] values2 = {2, 1, 3, null, 4, null, 7};
        TreeNode t1 = createTree(values1);
        TreeNode t2 = createTree(values2);
        System.out.println("Tree 1: ");
        printTree(t1);
        System.out.println("Tree 2: ");
        printTree(t2);
        TreeNode mergedTree = solution.mergeTrees(t1, t2);
        System.out.println("Merged Tree: ");
        printTree(mergedTree);
    }
}